Repository navigation
Conversation
The reader only stores a pointer into the string, which dangles once the temporary is destroyed. pbf_message's forwarding constructor is now constrained so it inherits this.
Member
Author
|
(@joto FYI, in preparation for a 1.9 release of protozero, I'm continuing the theme of small-ish code and documentation fixes that make it harder to misuse the protozero API, and fix subtle bugs that occur once you use protozero to create/parse billions of protobuf files) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pbf_readeronly stores a pointer into thestd::stringit is constructed from. Constructing it from a temporary string compiled fine, but the reader pointed to freed memory as soon as the temporary was destroyed:protozero::pbf_reader message{read_file("data.pbf")}; // dangles while (message.next()) { ... } // use after freeThe same happened with
pbf_message, since it forwards all constructor arguments topbf_reader.This PR contains the following changes:
pbf_reader(const std::string&&)is now deleted. It also catches non-const temporaries, since they prefer binding toconst std::string&&overconst std::string&.pbf_messageis now only enabled ifpbf_readeris constructible from the arguments. Previously,std::is_constructiblereportedtruefor any arguments, and errors only showed up when the constructor body was instantiated.static_asserts intest_basic.cppthat check both classes can be constructed from astd::stringlvalue, but not from a temporary.